package ru.rchervot.sanasar.client.event;

import ru.rchervot.sanasar.client.model.Query;

import com.google.gwt.event.shared.GwtEvent;

public class EventQueryChange extends GwtEvent<HandlerQueryChange> {
	private static Type<HandlerQueryChange> TYPE = new Type<HandlerQueryChange>();
	
	private Query query;
	
	public EventQueryChange() {}
	
	public EventQueryChange(Query query) {
		this.query = query;
	}
	
	@Override
	protected void dispatch(HandlerQueryChange handler) {
		handler.onQueryChange(this);
	}

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static Type<HandlerQueryChange> getType() {
		if (TYPE == null) {
			TYPE = new Type<HandlerQueryChange>();
		}
		return TYPE;
	}

	// The instance knows its PlaceChangeEventHandler is of type T, but the TYPE
	// field itself does not, so we have to do an unsafe cast here.
	@SuppressWarnings("unchecked")
	@Override
	public Type<HandlerQueryChange> getAssociatedType() {
		return (Type) TYPE;
	}

	public Query getQuery() {
		return query;
	}
	
	public static EventQueryChange build(Query query) {
		return new EventQueryChange(query);
	}

}